import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { ElMessage } from 'element-plus'
const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Layout',
        component: () => import('@/views/index.vue'),
        redirect: '/patientManage',
        children: [
            {
                path: '/patientManage',
                name: 'patientManage',
                component: () => import('@/views/patientManage/index.vue'),
            },
            {
                path: '/addPatient',
                name: 'addPatient',
                component: () => import('@/views/patientManage/addPatient/index.vue'),
            },
            {
                path: '/editPatient',
                name: 'editPatient',
                component: () => import('@/views/patientManage/editPatient/index.vue'),
            },
            {
                path: '/patientMessage',
                name: 'patientMessage',
                component: () => import('@/views/patientManage/patientMessage/index.vue'),
            },
            {
                path: '/eyeTrackingRecord',
                name: 'eyeTrackingRecord',
                component: () => import('@/views/report/index.vue'),
            },
            {
                path: '/systemSettings',
                name: 'systemSettings',
                component: () => import('@/views/hospitalManage/index.vue'),
            },
            {
                path: '/accessControl',
                name: 'accessControl',
                component: () => import('@/views/accountManage/index.vue'),
            },
            {
                path: '/eyeTrackingView',
                name: 'eyeTrackingView',
                component: () => import('@/views/eyeTracking/index.vue'),
            },
            {
                path: '/reportTemplate',
                name: 'reportTemplate',
                component: () => import('@/views/report/reportTemplate/index.vue'),
            },
        ]
    },
    {
        path: '/startTest',
        name: 'startTest',
        component: () => import('@/views/report/task/index.vue'),
    },
    {
        path: '/constructor',
        name: 'constructor',
        component: () => import('@/views/report/constructor/index.vue'),
    },
    // {
    //     path: '/reportView',
    //     name: 'reportView',
    //     component: () => import('@/views/report/reportView.vue'),
    // },
    // {
    //     path:'/home',
    //     name:'Home',
    //     component:()=>import ('@/views/home/index.vue'),
    //     meta:{
    //         isHidden:false
    //     }
    // },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
        meta: {
            isHidden: true
        }
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to,from,next) => {
    if (sessionStorage.getItem('token')) {
        if (to.name === 'login') next('/')
        else next()
    } else {
        if (to.name === 'login') next()
        else {
            ElMessage({
                message: '请先登录',
                type: 'warning'
            })
            next('/login')
        }
    }
})
export default router